const { feedback } = require('../models/index');

class Feedback {
  static async submit(ctx) {
    const { request: { body: feedMsg } } = ctx;
    if (!feedMsg.mobile || !feedMsg.cid) {
      ctx.body = {
        status: false,
        message: "缺少必填字段!"
      }
      return
    }
    if (!feedMsg.other_msg && !feedMsg.opid) {
      ctx.body = {
        status: false,
        message: "(问题选项/其他信息)不能同时为空!"
      }
      return
    }
    ctx.body = await feedback.submit(feedMsg);
  }
  static async list(ctx) {
    const { request: { query } } = ctx;
    if (Object.keys(query).length != 0) {
      const { pagination } = query;
      delete query.pagination;
      ctx.body = pagination ? await feedback.listCount({ body: query }) : await feedback.list(query);
      return
    }
    ctx.body = await feedback.list(false);
  }
}

module.exports = Feedback;